import axios, { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
// import authencation from '../plugins/authencation';

const instance = axios.create({
    timeout: 120000,
});


instance.interceptors.request.use(function (configure: InternalAxiosRequestConfig) {
    // configure.headers.Authorization = authencation.getToken()
    // console.log('axios configure', configure)

    return configure
}, function (error: any) {
    // console.log('error', error);

    return Promise.reject(error);
})

instance.interceptors.response.use(function (response: AxiosResponse) {
    // const {code} = (response || {}).data || {}
    // // 返回值是否OK
    // if (!['success', 200, '200'].includes(code)) {
    //     return Promise.reject(response?.data)
    // }
    return response.data
}, function (error: any) {
    const {code, message} = error.response?.data || {};
    return Promise.reject({code: code || 'system.error', message: message || error.message})
});

export default instance